<template>
  <div class="base-container">
    <!-- <t-form ref="form" :data="queryParams" label-width="80"
            @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="业务名称" name="businessName">
            <t-input
              v-model="queryParams.businessName"
              clearable
              placeholder="请输入项目名称"
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item v-if="!hideApproveType" label="业务类型" name="approveType">
            <t-select style="width: 240px" clearable v-model="queryParams.approveType"
                      :options="dict.type.approve_type">
            </t-select>
          </t-form-item>
          <t-form-item label="填报单位" name="deptName">
            <t-input
              v-model="queryParams.deptName"
              clearable
              placeholder="请输入填报单位"
              style="width: 240px"
            />
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form> -->
    <t-table rowKey="id" :data="data"
      :columns="!hideInfo ? columns : columns.filter(val => { return val.title !== '填报单位' })" hover
      :pagination="pagination" :loading="dataLoading" :sort="sort" :hideSortTips="true">
      <template #approveType="{ row }">
        {{ row.approveType | filterByDict(dict.type.approve_type) }}
      </template>

      <template #approveStatus="{ row }">
        <t-tag v-if="row.approveStatus"
          @click="dialog.header = row.projectName; dialog.standardCategory = row.standardCategory; dialog.objId = row.id; dialog.open_approve_list = true"
          class="cursor-pointer" :theme="handleTheme(row.approveStatus, dict.type.approve_status)" variant="light">
          {{ row.approveStatus | filterByDict(dict.type.approve_status) }}
        </t-tag>
        <t-tag @click="dialog.header = row.projectName; dialog.objId = row.id; dialog.open_approve_list = true"
          class="cursor-pointer" v-else theme="warning" variant="light">未提交
        </t-tag>
      </template>

      <template #op="{ row }">
        <t-button @click="dialog.row = row; dialog.open = true" size="small" variant="text" class="t-button-link">
          <t-icon name="edit-1" slot="icon" />
          审批
        </t-button>
      </template>
    </t-table>
    <approve-info :visible.sync="dialog.open" @reload="getList()" :row="dialog.row" v-if="dialog.open">
    </approve-info>

  </div>
</template>

<script>
import ApproveInfo from "./components/approve-info.vue"


export default {
  name: "index",
  dicts: ["approve_type", "project_status"],
  components: {
    ApproveInfo,
  },
  data () {
    return {
      sort: [],
      hideApproveType: false,
      hideInfo: this.$store.state.user.roles.includes("xssc"),
      dialog: {
        open: false,
        header: "",
        row: {},
        data: {},
        open_project_detail: false,
        open_outline_detail: false,
        open_contract_detail: false,
        objId: 0,
        open_approve_list: false,
        tabDefaultValue: '1',
        open_item_detail: false,
        open_new_contract_detail: false,
        current_open_project_detail: false,
        current_open_project_detail_new: false
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        approveType: '',
        businessName: '',
        deptName: ''
      },
      data: [],
      columns: [
        {
          colKey: "talents.name",
          title: "人才姓名",
          align: "center",
          width: 200
        },
        {
          colKey: "businessName",
          title: "业务名称",
          align: "center",
          // ellipsis: true,
          width: 220,
          // sorter: true,
        },
        {
          colKey: "approveType",
          title: "审批业务类型",
          align: "center",
          width: 120
        },
        {
          colKey: "approveStatus",
          title: "审批结果",
          align: "center",
          width: 180,
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 200
        },
      ],

      dataLoading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  async created () {

    this.getList()
  },
  methods: {

    getList () {
      this.dataLoading = true;
      this.$api.kjrc.approve.myApprovedlist(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },

  },
}
</script>

<style scoped></style>
